package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    @Insert("insert into shopping_cart(id, name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time)" +
            "values(#{id}, #{name}, #{image}, #{userId}, #{dishId}, #{setmealId} ,#{dishFlavor} ,#{number} ,#{amount} ,#{createTime})")
    int insert(ShoppingCart shoppingCart);


    @Select("select *from shopping_cart where user_id = #{id}")
    List<ShoppingCart> selectById(Long id);

    @Select("select *from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> selectByUserId(Long userId);

    ShoppingCart selectByUserIdWithDishIdOrSetmealId(@Param("dto") ShoppingCartDTO shoppingCartDTO,@Param("userId") Long userId);

    /**
     * 更新购物车商品
     * @param existingItem 购物车商品对象
     */
    int update(ShoppingCart existingItem);

    /**
     * 根据用户id进行珊瑚购物车商品
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteByUserId(Long userId);

    /**
     * 根据商品id进行删除
     * @param id
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据购物车对象参数查询数据
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> selectList(ShoppingCart shoppingCart);

    /**
     * 批量插入
     *
     * @param shoppingCarts
     */
    int insertBatch(List<ShoppingCart> shoppingCarts);
}
